import { Menu, getCurrentWindow } from "@electron/remote"

//创建右键菜单
function useContextMenu(contextMenuTemp, areaClass, currentEle) {
    const menu = Menu.buildFromTemplate(contextMenuTemp)
    const contextMenuHandle = (ev) => {
        //获取需要触发右键菜单的区域元素
        const araeEle = document.querySelector(areaClass)
        if (araeEle && araeEle.contains(ev.target)) {
            menu.popup({ window: getCurrentWindow() })
            if (currentEle)
                currentEle.current = ev.target
        }

    }
    window.addEventListener("contextmenu", contextMenuHandle)
    return () => {
        window.removeEventListener("contextmenu", contextMenuHandle)
    }
}
export default useContextMenu
